package main

import (
	"fmt"
	"time"
)

/*
golang定时器
*/
func main() {
	//time.Now()
	//ticker := time.NewTicker(time.Second)
	//
	////ticker.C
	//var num = 0
	//for t := range ticker.C {
	//	fmt.Println(t)
	//	num++
	//	if num == 5 {
	//		ticker.Stop() //终止这个定时器继续执行
	//		break
	//	}
	//}

	//休眠方法
	//fmt.Println("aaa")
	//time.Sleep(time.Second)
	//fmt.Println("aaa2")
	//time.Sleep(time.Second)
	//fmt.Println("aaa3")
	//time.Sleep(time.Second)
	//fmt.Println("aaa4")
	//time.Sleep(time.Second * 5)
	//fmt.Println("aaa")
	//fmt.Println("aaa")
	//fmt.Println("aaa")
	//fmt.Println("aaa")
	//fmt.Println("aaa")
	//fmt.Println("aaa")

	num := 0
	for {
		time.Sleep(time.Second)
		fmt.Println("我在定时执行任务")
		num++
		if num > 10 {
			//直接停止循环，不需要销毁ticker
			break
		}
	}
}
